 var table ,form ,laypage ,layer ,element ,laydate ,upload//时间组件 
 var check=true; 
$(function(){
	var iddata=getQueryString("iddata");
	layui.use(['table','form','laypage','layer', 'element', 'laydate','upload'], function(){
         table = layui.table;
         form=layui.form;
         laypage = layui.laypage ;//分页
         layer = layui.layer ;//弹层
         element = layui.element; //元素操作
         laydate = layui.laydate; //时间组件 
         upload = layui.upload;
         dictPublicfun();
         selectStation();
		//监听表格数据
		table.render({
		    elem: '#tabledata',
		    height: $(window).height()-200,		   
		    text: {
			    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
			  },
			method: 'post',  
			loading: true,
		    url: '/equipmentKnowledge/getList.do' ,//数据接口,
		    headers: setHeader(),
		    parseData: function(res){
		    	   return res.resultData;
            },
            response: {
                statusName: 'status', //规定数据状态的字段名称，默认：code
                statusCode: 200, //规定成功的状态码，默认：0
                msgName: 'hint', //规定状态信息的字段名称，默认：msg
                countName: 'total', //规定数据总数的字段名称，默认：count
                dataName: 'data' //规定数据列表的字段名称，默认：data
            },
		    page: true, //开启分页
		    cols: [[    //表头	 
			      {field: 'id', title: 'ID',   align:'center',hide:true,width:5},
			      {field: 'xuhao', title: '序号',  align:'center', type:'numbers',width:20},
			      {field: 'equipmentName', title: '设备名称', align:'left',width:300},
			      {field: 'equipmentCode', title: '设备编码', align:'left',width:150},
			      {field: 'stationName', title: '所属变电站', align:'left',width:150},
			      {field: 'typeZh', title: '知识库类型',   align:'left',width:150},
			      {field: 'remarks', title: '故障备注', align:'left',width:150},
			      {field: 'createName', title: '创建人 ', align:'left',align:'left',width:150},
			      {field: 'createTime', title: '创建时间', align:'left',width:180,
			    	  templet: function(data){
				  			return changeTime(data.createTime)					        							        
				  		}  
			      },			      
			      {field: '', title: '操作', align:'center',width:180,fixed:'right',
				      templet: function(data){
						return '<div class="layui-btn-group">'+
						'<a href="javascript:;" class="layui-btn layui-btn-warm layui-btn-xs BTNSHOW BTNSHOW_EDIT " lay-event="edit">编辑</a>'+
					                    '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs BTNSHOW BTNSHOW_LOOK " lay-event="look"  >查看</a>' +
					                    '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs BTNSHOW BTNSHOW_DELETE" lay-event="del"  >删除</a>'+                             
                               '</div>'   
						}
			      }
			    ]],
		    done: function (res) {
		    	 permissionFUN()//功能按钮权限
                if(res.status!=200){
                	$(".layui-none").text(res.resultMsg)
                }
            }
		});
		//监听行工具事件
        table.on('tool(test)', function (obj) {
			form.render();//需要渲染一下
            var data = obj.data;
          //编辑删除功能
            if (obj.event === 'del') {  //删除
                layer.confirm('真的要删除这行数据？', function (index) {
                	 var requestData = {"id": data.id, "other":data};
              	  	$.ajax({
          	           url: "/equipmentKnowledge/deleteEquipmentKnowledge.do",               //请求地址
          	           type: "POST",              //请求类型
          	           data:formatParam(requestData),              //请求数据
          	           timeout: 200000,                //请求超时时间(毫秒)
          	           headers: setHeader(),
          	           success:function(res){         //请求成功
          	        	   if(res.status == 200)
          	  				{
          	    				layer.msg(res.resultMsg, {icon: res.icon},function(){
          	    					 layer.closeAll();//关闭加载层
          	    					table.reload("tabledata", {});
          						}); 					
          	  				}else if(res.status == 666){
          	  					TIMEOUT(); 
          	  		        }else{
          	  					layer.msg(res.resultMsg, {icon: res.icon});
          	  				}
          	  				      
                        }
                     })
                    return false;
                });
            }else if (obj.event === 'look') {
            	var num = obj.data;
            	var fullindex=layer.open({
   			        type: 2,
   			        area: ['100%', '100%'],
   			        fix: false, //不固定
   			        maxmin: true,
   			        shadeClose: true,
   			        shade:0.4, //遮罩层
   			        title: ['设备知识库查看','background:#1E9FFF;color:#fff'],
   			        content: '/res/page/equipmentKnowledge/equipmentKnowledge_look.html?id='+num.id
   			    });
            	layer.full(fullindex);
            	form.render();   
            }else if (obj.event === 'edit') {
            	var num = obj.data;
            	 var fullindex1=layer.open({
  			        type: 2,
  			        area: ['100%', '100%'],
  			        fix: false, //不固定
  			        maxmin: true,
  			        shadeClose: true,
  			        shade:0.4, //遮罩层
  			        title: ['知识库修改','background:#1E9FFF;color:#fff'],
  			        content: "/res/page/equipmentKnowledge/equipmentKnowledge_form.html?id="+num.id+'&permissionId='+permissionId
  			    });	
            	layer.full(fullindex1);
  			    form.render();        	
            } 
			form.render();//需要渲染一下	   
        });    
	    // 查询按钮提交查询信息
	    form.on('submit(queryData)', function(data){
	    	// 组装查询条件
	        var reqData = getConditionValue();
	        // 重新加载表格数据
	        table.reload("tabledata", {
	             where: {"reqData" : JSON.stringify(reqData)}
		         ,page: {
		            curr: 1 //重新从第 1 页开始
		          }
	        });
	        
	    });
	});
})
